<!--********************************************************************
* Copyright© 2000 - 2025 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title data-i18n="resources.title_defaultStyle"></title>
    <style type="text/css">
        body {
            margin: 0;
            overflow: hidden;
            background: #fff;
            width: 100%;
            height: 100%
        }

        #map {
            position: absolute;
            width: 100%;
            height: 100%;
        }

        #toolbar {
            position: absolute;
            top: 50px;
            right: 10px;
            width: 300px;
            text-align: center;
            z-index: 100;
            border-radius: 4px;
        }

        .input-group {
            margin-bottom: 15px;
        }
    </style>
</head>
<body>
<div id="toolbar" class="panel panel-primary">
    <div class='panel-heading'>
        <h5 class='panel-title text-center' data-i18n="resources.title_defaultStyle"></h5></div>
    <div class='panel-body content'>
        <div class='panel'>
            <div class='input-group'>
                <span class='input-group-addon' data-i18n="resources.text_lineWidth"></span>
                <input type='text' class='form-control' id='lineWidth' value='2' onchange="lineWidthChanges()"/>
            </div>
            <div class='input-group'>
                <span class='input-group-addon' data-i18n="resources.text_lineType"></span>
                <select class='form-control' id='lineStyle' onchange="lineStyleChanges()">
                    <option value='solid'>solid</option>
                    <option value='dot'>dot</option>
                    <option value='dash'>dash</option>
                    <option value='dashdot'>dashdot</option>
                    <option value='longdash'>longdash</option>
                    <option value='longdashdot'>longdashdot</option>
                </select>
            </div>
            <div class='input-group'>
                <span class='input-group-addon' data-i18n="resources.text_lineColor"></span>
                <input type="text" id="lineColor" value="" class='form-control'/>
                <span class='input-group-addon'><img src='images/colorpicker.png' id="cp1"
                                                     style="cursor:pointer"/></span>
            </div>
            <div class='input-group'>
                <span class='input-group-addon' data-i18n="resources.text_markerWidth"></span>
                <input type='text' class='form-control' id='symbolWidth' value='40' onchange="symbolWidthChanges()"/>
            </div>
            <div class='input-group'>
                <span class='input-group-addon' data-i18n="resources.text_markerHeight"></span>
                <input type='text' class='form-control' id='symbolHeight' value='40' onchange="symbolHeightChanges()"/>
            </div>
            <div class='input-group'>
                <span class='input-group-addon' data-i18n="resources.text_defaultStyle"></span>
                <select class='form-control' id='defaultStyleFlag' onchange="defaultStyleFlagChanges()">
                    <option value='0'>false</option>
                    <option value='1'>true</option>
                </select>                                           
            </div>
        </div>
        <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_drawMarker" onclick="drawPolygon()"/>
        <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_cancelMarker" onclick="cancel()"/>
    </div>
</div>
<div id="map"></div>
<script type="text/javascript" include="bootstrap,responsive,colorpicker" src="../js/include-web.js"></script>
<script type="text/javascript" exclude="iclient-classic" include="iclient8c-plot" src="../../dist/classic/include-classic.js"></script>
<script>
    var map, baseLayer, plottingLayer, drawFeature, plotting, plottingEdit;
    var host = window.isLocal ? window.server : "https://iserver.supermap.io";
    var mapurl = host + "/iserver/services/map-world/rest/maps/World";
    var serverUrl = host + "/iserver/services/plot-jingyong/rest/plot/";
    init();

    function init() {
        map = new SuperMap.Map("map", {
            controls: [
                new SuperMap.Control.ScaleLine(),
                new SuperMap.Control.Zoom(),
                new SuperMap.Control.Navigation({
                    dragPanOptions: {
                        enableKinetic: true
                    }
                })]
        });
        map.addControl(new SuperMap.Control.LayerSwitcher(), new SuperMap.Pixel(42, 80));
        baseLayer = new SuperMap.Layer.TiledDynamicRESTLayer("World", mapurl, {
            transparent: true,
            cacheEnabled: true
        }, {maxResolution: "auto"});
        baseLayer.events.on({"layerInitialized": addLayer});

        plottingLayer = new SuperMap.Layer.PlottingLayer("PlottingLayer", serverUrl);
        drawFeature = new SuperMap.Control.DrawFeature(plottingLayer, SuperMap.Handler.GraphicObject);

        //态势标绘编辑
        plottingEdit = new SuperMap.Control.PlottingEdit();
        map.addControls([drawFeature, plottingEdit]);
    }

    function addLayer() {
        map.addLayers([baseLayer, plottingLayer]);
        map.setCenter(new SuperMap.LonLat(0, 0), 0);

        plotting = SuperMap.Plotting.getInstance(map, serverUrl);
        plottingEdit.activate();
        var symbolLibManager = plotting.getSymbolLibManager();
        if (symbolLibManager.isInitializeOK()) {
            initHtml();
        } else {
            function initializeCompleted(result) {
                initHtml();
            }

            symbolLibManager.events.on({
                "initializeCompleted": initializeCompleted,
                scope: this
            });
            symbolLibManager.initializeAsync();
        }

    }

    function initHtml() {
        document.getElementById("lineWidth").value = plotting.getDefaultStyle().lineWidth;
        document.getElementById("lineStyle").value = plotting.getDefaultStyle().lineType;
        document.getElementById("lineColor").value = plotting.getDefaultStyle().lineColor;
        document.getElementById("symbolWidth").value = plotting.getDefaultStyle().dotSymbolSize;
        document.getElementById("symbolHeight").value = plotting.getDefaultStyle().dotSymbolSize;
        if (plotting.getDefaultStyle().defaultFlag)
            document.getElementById("defaultStyleFlag").value = 1;
        else
            document.getElementById("defaultStyleFlag").value = 0;
    }

    function cancel() {
        drawFeature.deactivate();
    }

    function lineWidthChanges() {
        cancel();
        plotting.getDefaultStyle().lineWidth = document.getElementById("lineWidth").value;
    }

    function lineStyleChanges() {
        cancel();
        plotting.getDefaultStyle().lineType = document.getElementById("lineStyle").value;
    }

    function symbolWidthChanges() {
        cancel();
        plotting.getDefaultStyle().dotSymbolSize = document.getElementById("symbolWidth").value;
        document.getElementById("symbolHeight").value = plotting.getDefaultStyle().dotSymbolSize;
    }

    function symbolHeightChanges() {
        cancel();
        plotting.getDefaultStyle().dotSymbolSize = document.getElementById("symbolHeight").value;
        document.getElementById("symbolWidth").value = plotting.getDefaultStyle().dotSymbolSize;
    }

    function defaultStyleFlagChanges() {
        cancel();
        if (document.getElementById("defaultStyleFlag").selectedIndex === 0) {
            plotting.getDefaultStyle().defaultFlag = false;
        } else {
            plotting.getDefaultStyle().defaultFlag = true;
        }
        //plotting.getDefaultStyle().defaultFlag = document.getElementById("defaultStyleFlag").selectedIndex;
    }

    function drawPolygon() {
        drawFeature.handler.serverUrl = serverUrl;
        drawFeature.handler.libID = 421;
        drawFeature.handler.symbolCode = 20100;
        drawFeature.deactivate();
        drawFeature.activate();
    }

    $(document).ready(function () {
        $("#cp1").colorpicker({
            ishex: true,
            fillcolor: true,
            event: 'mouseover',
            target: $("#lineColor"),
            success: lineColorChanges

        });
        $("#_creset").css("font-size", "12px");
        $("#_creset").css("padding-right", "20px");
        $("#colorpanel").css({"z-index": "100"});
    });

    function lineColorChanges() {
        cancel();
        plotting.getDefaultStyle().lineColor = document.getElementById("lineColor").value;
    }

    function PlottingDrawCancel() {

        drawFeature.deactivate();
        plottingEdit.deactivate();
        plottingEdit.activate();

    }

    document.onmouseup = function (evt) {
        var evt = evt || window.event;
        if (evt.button === 2) {
            PlottingDrawCancel();
            return false;
        }
        evt.stopPropagation();
    }

</script>

</body>
</html>